package ecom.stateless;

import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import ecom.api.*;
import ecom.entity.*;

@Stateless(mappedName = "ecom.OptionPayanteStateless@Remote", description = "options payante stateless", name = "OptionPayanteStateless")
public class OptionPayanteStateless implements IOptionPayanteStatelessRemote {

    public OptionPayante optionpayante;
    @PersistenceContext
    private EntityManager m_EntityManager = null;   

    public List<OptionPayante> getListeOptionPayante() {
        return m_EntityManager.createQuery("select t from OptionPayante t").getResultList();
    }

    public OptionPayante getOptionPayanteByID(long id) {
        return (OptionPayante) m_EntityManager.createQuery("select t from OptionPayante t where t.id = '" + id + "'").getSingleResult();
    }

    public void removeOptionPayante(OptionPayante optionpayante) {
        m_EntityManager.remove(m_EntityManager.merge(optionpayante));
    }

    public void DeleteOptionPayante(long id) {
        m_EntityManager.createQuery("DELETE FROM OptionPayante c WHERE c.id= '" + id + "'").executeUpdate();
    }

    public OptionPayante ModifyPriceOptionPayante(long id, float prix, String desc, String nom, int duree) {
        optionpayante = m_EntityManager.find(OptionPayante.class, id);
        optionpayante.setPrix(prix);
        m_EntityManager.merge(optionpayante);
        return optionpayante;
    }

    public OptionPayante ModifyLifeCycleOptionPayante(long id, float prix, String desc, String nom, int duree) {
        optionpayante = m_EntityManager.find(OptionPayante.class, id);
        optionpayante.setDureedevie(duree);
        m_EntityManager.merge(optionpayante);
        return optionpayante;
    }
}
